#pragma once 

#include <geometry\primitives_fwd.h>

struct IViewerWindowEvent ; 


MIDL_INTERFACE ( "E46E17D8-4637-465f-B74B-3831F68A0E3C" )
IViewerWindow2D : IUnknown
{
  virtual void __stdcall Advise        ( IViewerWindowEvent * client ) = 0 ; 
  virtual void __stdcall Unadvise      () = 0 ; 

  virtual void __stdcall DoModal       ( HWND parent, LPCSTR name, LPRECT rect ) = 0 ;
  virtual void __stdcall RePaint       () = 0;
  
  virtual HWND __stdcall Create        ( HWND parent, LPCSTR name, LPCRECT rect ) = 0 ;
  virtual HWND __stdcall CreateControl ( HWND parent, LPCRECT rect ) = 0 ;

  virtual void __stdcall SetGlobalView ( double  x, double  y, double  ratio ) = 0 ;
  virtual void __stdcall GetGlobalView ( double *x, double *y, double *ratio ) = 0 ;
} ; 
   
MIDL_INTERFACE ( "B2ABF631-B747-4acb-8EE7-31AFF287DC62" )
IViewerWindowContext2D : IUnknown
{
  virtual void __stdcall GetClientRect ( long * sx0, long * sy0, long * sx1, long * sy1 ) = 0 ; 
  virtual BOOL __stdcall GetCursorPos  ( long * sx,  long * sy ) = 0 ; 

  virtual void __stdcall Screen2Global ( long  sx, long  sy, double * gx, double * gy ) = 0 ; 
  virtual void __stdcall Global2Screen ( double gx, double gy, long  * sx, long  * sy ) = 0 ; 

  virtual void __stdcall SetColor      ( cg::coloraf const& color ) = 0 ; 
  virtual void __stdcall SetColor      ( cg::colorf const& color, float a ) = 0 ; 
  virtual void __stdcall SetColorHSV   ( float h, float s, float v, float a ) = 0 ; 
  virtual void __stdcall SetBGColor    ( cg::coloraf const & color ) = 0; 
  virtual void __stdcall SetTextColor  ( cg::coloraf const & color ) = 0; 

  // screen methods 
  virtual void __stdcall Line          ( long sx0, long sy0, long sx1, long sy1 ) = 0 ;

  virtual void __stdcall FillRect      ( long sx0, long sy0, long sx1, long sy1 ) = 0 ; 
  
  virtual void __stdcall PutText       ( long sx, long sy, LPCSTR text, size_t fonstIdx = 0 ) = 0 ; 
  virtual void __stdcall GetTextExtent ( LPCSTR text, long * sx, long * sy ) = 0 ; 

  // global methods
  virtual void __stdcall Polyline       ( const cg::point_2 * points, float width, DWORD count    , const cg::coloraf * colors = NULL, const float * u = NULL ) = 0 ; 
  virtual void __stdcall PolyWithArrows ( const cg::point_2 * points, float width, DWORD count    , const cg::coloraf * colors = NULL, const float * u = NULL ) = 0 ; 
  virtual void __stdcall Pixels         ( const cg::point_2 * points, float width, DWORD count = 1, const cg::coloraf * colors = NULL, const float * u = NULL ) = 0 ; 
  virtual void __stdcall Lines          ( const cg::point_2 * points, float width, DWORD count = 1, const cg::coloraf * colors = NULL, const float * u = NULL ) = 0 ; 
  virtual void __stdcall LinesWithArrows( const cg::point_2 * points, float width, DWORD count = 1, const cg::coloraf * colors = NULL, const float * u  = NULL) = 0 ; 
  virtual void __stdcall Triangles      ( const cg::point_2 * points, BOOL fill,   DWORD count = 1, const cg::coloraf * colors = NULL, const float * u = NULL ) = 0 ; 
  virtual void __stdcall Rectangles     ( const cg::point_2 * points, BOOL fill,   DWORD count = 1, const cg::coloraf * colors = NULL, BOOL tex = FALSE ) = 0 ; // tex allows to draw rectangle with selected 2d texture 
  virtual void __stdcall Circle         ( const cg::point_2 * center, double radius ) = 0 ;

  virtual void __stdcall InitFonts     ( LOGFONT *fonts, int count ) = 0;
  virtual void __stdcall PutTextGlobal ( const cg::point_2 * point, LPCSTR text, size_t fonstIdx = 0 ) = 0 ; 

  virtual int  __stdcall StartMacro    () = 0 ; 
  virtual void __stdcall EndMacro      () = 0 ; 
  virtual void __stdcall PlayMacro     ( int id ) = 0 ; 
  virtual void __stdcall DeleteMacro   ( int id ) = 0 ; 

  virtual void __stdcall SetAnimation  ( DWORD delay ) = 0 ;  // ms, delay == 0 - no animation
  
  // textures 
  virtual DWORD __stdcall CreateTexture ( HBITMAP hPicture, HBITMAP hAlpha ) = 0 ; 
  virtual void  __stdcall DeleteTexture ( DWORD id ) = 0 ; 
  virtual DWORD __stdcall SelectTexture ( DWORD id ) = 0 ; 
} ; 

MIDL_INTERFACE ( "B6C9F20F-EB31-4cb7-A3D9-93C83FEC4850" )
IViewerWindowEvent : IUnknown
{
  virtual void __stdcall OnDraw   () = 0 ; 
  virtual void __stdcall OnMove   ( BOOL * redraw ) = 0 ; 
  virtual BOOL __stdcall OnButton ( BOOL left, BOOL down, BOOL * redraw ) = 0 ; 
  virtual BOOL __stdcall OnKey    ( DWORD vkey, BOOL down, BOOL * redraw ) = 0 ; 
  virtual void __stdcall OnDestroy() = 0 ;
} ; 

_COM_SMARTPTR_TYPEDEF(IViewerWindow2D,        __uuidof(IViewerWindow2D        ) );
_COM_SMARTPTR_TYPEDEF(IViewerWindowContext2D, __uuidof(IViewerWindowContext2D ) );
_COM_SMARTPTR_TYPEDEF(IViewerWindowEvent,     __uuidof(IViewerWindowEvent     ) );

MIDL_INTERFACE("F65BF234-F993-4ff1-B35F-AB7AEC404282") ViewerWindow2D; 
